from django.db import models
from django.utils import timezone
# Create your models here.


class User(models.Model):
    GENDER_CHOICE = (
        ('male', '男'),  # 默认第一项存到数据表中
        ('female', '女'),
        ('unknown', '未知')
    )
    # 主键id自增，自动创建
    name = models.CharField('用户名', max_length=20)
    password = models.CharField('密码', max_length=20)
    hash_password = models.CharField('哈希密码', max_length=128)
    gender = models.CharField('性别', choices=GENDER_CHOICE, max_length=20, default=GENDER_CHOICE[2][0])
    email = models.CharField('邮箱', max_length=100)
    register_time = models.DateTimeField('注册日期', default=timezone.now)
    # phone = models.CharField('手机号', max_length=20)
    # last_login_time = models.CharField('最后登录时间')
    # is_active = models.CharField('')

    def __str__(self):
        # 默认<class User>，重写此方法可以在调试时看到实例的name属性
        return '<class User>{}'.format(self.name)

    class Meta:
        # db_table = ''  # 默认生成 模块名_类名的表  login_user
        # ordering = ''   # order by
        verbose_name = '用户表'


